package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.system.domain.vo.IcEventVo;
import com.ruoyi.system.service.WeChatService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.IcEvent;
import com.ruoyi.system.service.IIcEventService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 事件Controller
 * 
 * @author ruoyi
 * @date 2024-07-04
 */
@Controller
@RequestMapping("/system/icEvent")
public class IcEventController extends BaseController
{
    private String prefix = "system/icEvent";

    @Autowired
    private IIcEventService icEventService;

    @RequiresPermissions("system:icEvent:view")
    @GetMapping()
    public String icEvent()
    {
        return prefix + "/icEvent";
    }

    /**
     * 查询事件列表
     */
    @RequiresPermissions("system:icEvent:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IcEvent icEvent)
    {
        startPage();
        List<IcEventVo> list = icEventService.selectIcEventListVO(icEvent);
        return getDataTable(list);
    }

    /**
     * 导出事件列表
     */
    @RequiresPermissions("system:icEvent:export")
    @Log(title = "事件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IcEvent icEvent)
    {
        List<IcEvent> list = icEventService.selectIcEventList(icEvent);
        ExcelUtil<IcEvent> util = new ExcelUtil<IcEvent>(IcEvent.class);
        return util.exportExcel(list, "事件数据");
    }

    /**
     * 新增事件
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存事件
     */
    @RequiresPermissions("system:icEvent:add")
    @Log(title = "事件", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IcEvent icEvent)
    {
        return toAjax(icEventService.insertIcEvent(icEvent));
    }

    /**
     * 修改事件
     */
    @RequiresPermissions("system:icEvent:edit")
    @GetMapping("/edit/{eId}")
    public String edit(@PathVariable("eId") Long eId, ModelMap mmap)
    {
        IcEvent icEvent = icEventService.selectIcEventByEId(eId);
        mmap.put("icEvent", icEvent);
        return prefix + "/edit";
    }

    /**
     * 修改保存事件
     */
    @RequiresPermissions("system:icEvent:edit")
    @Log(title = "事件", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IcEvent icEvent)
    {
        return toAjax(icEventService.updateIcEvent(icEvent));
    }

    /**
     * 删除事件
     */
    @RequiresPermissions("system:icEvent:remove")
    @Log(title = "事件", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(icEventService.deleteIcEventByEIds(ids));
    }
}
